package at.horario.util;

import net.sf.jxls.transformer.XLSTransformer;
import org.apache.commons.beanutils.BeanUtils;
import org.apache.commons.lang.math.RandomUtils;
import static org.apache.commons.lang.math.RandomUtils.nextInt;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.core.io.ClassPathResource;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.lang.reflect.InvocationTargetException;

/**
 * Created by IntelliJ IDEA.
 * User: AT
 * Date: Oct 7, 2007
 * Time: 12:47:40 PM
 * To change this template use File | Settings | File Templates.
 */
public class ExcelRow {
    private String cel;
    private String cel1, cel2, cel3, cel4, cel5, cel6, cel7, cel8, cel9, cel10, cel11, cel12, cel13, cel14, cel15, cel16, cel17, cel18, cel19, cel20, cel21, cel22, cel23, cel24, cel25, cel26, cel27, cel28, cel29, cel30;

    public String getCel() {
        return cel;
    }

    public void setCel(String cel) {
        this.cel = cel;
    }

    public String getCel1() {
        return cel1;
    }

    public void setCel1(String cel1) {
        this.cel1 = cel1;
    }

    public String getCel2() {
        return cel2;
    }

    public void setCel2(String cel2) {
        this.cel2 = cel2;
    }

    public String getCel3() {
        return cel3;
    }

    public void setCel3(String cel3) {
        this.cel3 = cel3;
    }

    public String getCel4() {
        return cel4;
    }

    public void setCel4(String cel4) {
        this.cel4 = cel4;
    }

    public String getCel5() {
        return cel5;
    }

    public void setCel5(String cel5) {
        this.cel5 = cel5;
    }

    public String getCel6() {
        return cel6;
    }

    public void setCel6(String cel6) {
        this.cel6 = cel6;
    }

    public String getCel7() {
        return cel7;
    }

    public void setCel7(String cel7) {
        this.cel7 = cel7;
    }

    public String getCel8() {
        return cel8;
    }

    public void setCel8(String cel8) {
        this.cel8 = cel8;
    }

    public String getCel9() {
        return cel9;
    }

    public void setCel9(String cel9) {
        this.cel9 = cel9;
    }

    public String getCel10() {
        return cel10;
    }

    public void setCel10(String cel10) {
        this.cel10 = cel10;
    }

    public String getCel11() {
        return cel11;
    }

    public void setCel11(String cel11) {
        this.cel11 = cel11;
    }

    public String getCel12() {
        return cel12;
    }

    public void setCel12(String cel12) {
        this.cel12 = cel12;
    }

    public String getCel13() {
        return cel13;
    }

    public void setCel13(String cel13) {
        this.cel13 = cel13;
    }

    public String getCel14() {
        return cel14;
    }

    public void setCel14(String cel14) {
        this.cel14 = cel14;
    }

    public String getCel15() {
        return cel15;
    }

    public void setCel15(String cel15) {
        this.cel15 = cel15;
    }

    public String getCel16() {
        return cel16;
    }

    public void setCel16(String cel16) {
        this.cel16 = cel16;
    }

    public String getCel17() {
        return cel17;
    }

    public void setCel17(String cel17) {
        this.cel17 = cel17;
    }

    public String getCel18() {
        return cel18;
    }

    public void setCel18(String cel18) {
        this.cel18 = cel18;
    }

    public String getCel19() {
        return cel19;
    }

    public void setCel19(String cel19) {
        this.cel19 = cel19;
    }

    public String getCel20() {
        return cel20;
    }

    public void setCel20(String cel20) {
        this.cel20 = cel20;
    }

    public String getCel21() {
        return cel21;
    }

    public void setCel21(String cel21) {
        this.cel21 = cel21;
    }

    public String getCel22() {
        return cel22;
    }

    public void setCel22(String cel22) {
        this.cel22 = cel22;
    }

    public String getCel23() {
        return cel23;
    }

    public void setCel23(String cel23) {
        this.cel23 = cel23;
    }

    public String getCel24() {
        return cel24;
    }

    public void setCel24(String cel24) {
        this.cel24 = cel24;
    }

    public String getCel25() {
        return cel25;
    }

    public void setCel25(String cel25) {
        this.cel25 = cel25;
    }

    public String getCel26() {
        return cel26;
    }

    public void setCel26(String cel26) {
        this.cel26 = cel26;
    }

    public String getCel27() {
        return cel27;
    }

    public void setCel27(String cel27) {
        this.cel27 = cel27;
    }

    public String getCel28() {
        return cel28;
    }

    public void setCel28(String cel28) {
        this.cel28 = cel28;
    }

    public String getCel29() {
        return cel29;
    }

    public void setCel29(String cel29) {
        this.cel29 = cel29;
    }

    public String getCel30() {
        return cel30;
    }

    public void setCel30(String cel30) {
        this.cel30 = cel30;
    }


    public static void main(String[] args) throws IOException, InvocationTargetException, IllegalAccessException {
        List departmens = new ArrayList();
        // initilize list of departments in some way
        List<ExcelRow> rows = new ArrayList<ExcelRow>();
        for (int i = 0; i < 10; i++) {
            ExcelRow r = new ExcelRow();
            r.setCel("Professor-"+(i+1));
            for (int j = 0; j < 30; j++) {
                BeanUtils.setProperty(r, "cel" + (j + 1), String.valueOf(nextInt(30)));
            }
            rows.add(r);
        }
        Map beans = new HashMap();
        beans.put("rows", rows);
        XLSTransformer transformer = new XLSTransformer();
        //String templateFileName = "c:\\apps\\horario\\src\\main\\resources\\quadroprofessor.xls";
        //String destFileName = "c:\\temp\\teste.xls";
        ClassPathResource templateFileName = new ClassPathResource("quadroprofessor.xls");
        HSSFWorkbook t = transformer.transformXLS(templateFileName.getInputStream(), beans);
    }
}
